<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>注册</title>


	<link href="__PUBLIC__/css/default/index.css" rel="stylesheet" />
	<link href="__PUBLIC__/css/default/global.css?v=1" rel="stylesheet" />

	<script src="__JS__/jquery.min.js"></script>
	<link rel="stylesheet" href="__PUBLIC__/js/layer/layer.css" />
	<script src="__PUBLIC__/js/layer/layer.js"></script>




	<link rel="stylesheet" href="__CSS__/bootstrap.min.css">
	<link rel="stylesheet" href="__CSS__/font-awesome.min.css">
	<link rel="stylesheet" href="__CSS__/main.css">
	<link rel="stylesheet" href="__CSS__/animate.css">
	<link rel="stylesheet" href="__CSS__/responsive.css">



</head>
<body style="background-color: #f2f6fa;">
<header>
	<div class="container">
		<div class="row">
			<div class="col-md-3 col-xs-6 col-sm-3">
				<a href="/?/explore/index/" class="logo">
					<img src="__IMG__/logo.png" alt="">
				</a>
			</div>


		</div>
	</div>
</header>

<br/>
<br/>
<br/>
<div class="content">
	<div class="register_content">
		<div class="reg_title">
			<div class="title">用户注册</div>
			<div class="login_link">
				<span class="pt1">已有账户？</span>
				<a href="/login"><span class="pt2">登录</span></a>
			</div>
		</div>
		<div class="register-if">
			<div class="input_main">
				<div class="input_phone">
					<span class="left_it">手   机   号：  </span>
					<span class="input_tt"><input type="text" name="phone" id="rg_phone" placeholder="请输入手机号"></span>
				</div>

				<div class="input_phone">
					<span class="left_it">企业名字:&nbsp;</span>
					<span class="input_tt"><input type="text" name="phone" id="name" placeholder="请输入企业名字"></span>
				</div>

				<div class="input_phone">
					<span class="left_it">验 证 码：   </span>
					<span class="input_cd"><input type="text" id="rg_code" placeholder="输入验证码"></span>
					<span class="bt_cd" onclick="send_code();">获取验证码</span>
				</div>

				<div class="password fill_main input_phone">
					<span class="left_it">密&nbsp;&nbsp;&nbsp;&nbsp; 码：&nbsp;&nbsp;</span>
					<span class="input_tt"><input type="password" id="password"  placeholder="请输入你的密码"></span>
				</div>

			</div>
			<div class="login_btn">
				<span class="lgbtn" id="register_btn">下一步</span>
			</div>
			<div class="pt_tt">
				<!--<span class="pt1">注册代表你已同意</span>-->
				<!--<a href=""><span class="pt2">《用户协议》</span></a>-->
				<!--<span class="pt1">和</span>-->
				<!--<a href=""><span class="pt2">《隐私条款》</span></a>-->
			</div>
		</div>
	</div>

</div>


<script>
	$(function(){
		register();
		$(".id_option").click(function(){
			$(".sec").removeClass('active');
			$(this).find(".sec").addClass('active');
			$("input[name=identity]").attr('checked',false);
			$(this).find("input[name=identity]").prop("checked", "checked");
		});
	});
	function register(){
		$("#register_btn").click(function(){
			var phone=$("#rg_phone").val();
			var code=$("#rg_code").val();
			var name = $('#name').val();
			var password = $('#password').val();
			if(phone.length==0){
				showMsg('请输入手机号');
				return;
			}
			if(code.length==0){
				showMsg('请输入验证码');
				return;
			}
			if(name.length == 0){
				showMsg('请输入企业名字');
				return;
			}
			if(password.length == 0){
				showMsg('请输入密码');
				return;
			}


			var url = "/add_org"
			$.post(url,{"phone":phone,"code":code,"name":name,"password":password},function (result) {

				if(result.code == 200){
					layer.open({
						content: '您是否进行下一步认证企业？'
						,btn: ['认证', '下次']
						,yes: function(index){
							window.location.href="/company_data";
							layer.close(index);
						}
						,no:function (index) {
							window.location.href="/org_admin";
							layer.close(index);
						}
					});
				}else if(result.code == 100){
					showMsg('验证码错误');
				}
//				if(result.errno == 1){
//					window.location.href="/?/account/company_data/";
//				}else{
//					showMsg(result.err);
//				}
			},'json');



		});
	}
	/**
	 * 倒计时
	 */
	var wait = 60;
	var code_state = "IDLE";
	function count_down(){
		if(wait <= 0){
			$(".bt_cd").removeClass("active")
			$(".bt_cd").attr("onclick", "send_code()");
			$(".bt_cd").html("获取验证码");
			wait = 60;
			code_state = "IDLE";
		} else {
			$(".bt_cd").addClass("active")
			$(".bt_cd").attr("onclick", "");
			$(".bt_cd").html( "剩余" + wait + "秒");
			wait--;
			setTimeout(count_down, 1000);
		}
	}

	/**
	 * 发送短信验证码
	 */
	function send_code(){
		if (code_state != "IDLE"){
			return;
		}
		var tel = $.trim($("input[name='phone']").val());
		var reg = /^1[3|4|5|7|8][0-9]\d{8}$/;

		if(false == reg.test(tel)){
			showMsg('请输入正确的手机号');
			return ;
		}

		var url = "/api/user/sendRegCode?phone="+tel;
		$.get(url,function (result) {
			if(result.code == 200){
				code_state = "SENDING";
				count_down();
			}else if(result.code == 199){
				showMsg('注册手机号已存在');

			}else{
				showMsg('验证码发送失败');

			}
		},'json');



	}
	/**
	 * 显示消息
	 */
	function showMsg(msg,time) {
		layer.open({
			content: msg ,
			time: time ? time : 2 //3秒后自动关闭
		});
	}
</script>
</body>
</html>